// 导入二次封装axios
import http from '@/core/request/request.ts'
import { getAppType } from '@/core/lib/common'

// 统一管理接口
enum API {
  ADMIN_LOGIN = '/adminapi/login',
  SITE_LOGIN = '/adminapi/login',
  ADMIN_ROUTERS = '/adminapi/auth/user-menu',
  SITE_ROUTERS = '/siteapi/auth/user-menu',
  ADMIN_LOGIN_USER_INFO = '/adminapi/auth/user-info',
  SITE_LOGIN_USER_INFO = '/siteapi/auth/user-info',
  ADMIN_CONFIG = '/adminapi/auth/config',
  SITE_CONFIG = '/siteapi/auth/config',
}

// 登录接口方法
export const login = (params: any) => {
  return http.post(
    getAppType() == 'admin' ? API.ADMIN_LOGIN : API.SITE_LOGIN,
    params,
  )
}

// 获取后端菜单扁平化路由
export const listRouters = () => {
  return http.get(
    getAppType() == 'admin' ? API.ADMIN_ROUTERS : API.SITE_ROUTERS,
  )
}

// 获取角色数据 AND 按钮数据 AND 用户信息
export const getUserInfo = () => {
  return http.get(
    getAppType() == 'admin'
      ? API.ADMIN_LOGIN_USER_INFO
      : API.SITE_LOGIN_USER_INFO,
  )
}

// 获取基础配置
export const getInitConfig = () => {
  return http.get(getAppType() == 'admin' ? API.ADMIN_CONFIG : API.SITE_CONFIG)
}
